<template>
    <div class="PBSdiv1">
    <el-row class="myCreateOrderrow15" type="flex" justify="center">
        <el-col :span="14" class="myCreateOrdercol15Left">
            <div class="PBSdiv2">请在倒计时结束前结算
                <el-tooltip content="● 好商品需要精挑细选，特意为你留足20分钟考虑时间；" placement="top-end" effect="light">
                    <span><i class="el-icon-question" style="color:blue;"></i></span>
                </el-tooltip>
            </div>
        </el-col>
        <el-col :span="10" class="myCreateOrdercol15Right">
            <div class="PBSdiv3" @click="HavedOrder">提交订单
                <span class="COpaytime">09 : 35</span>
            </div>
        </el-col>
    </el-row>
    </div>
</template>

<script>
    export default {
        name:'PxCOPayInfoBtnShow',
        data(){
            return{
                PayBtnCids:'',  //下行解释出错,不可在此设置默认收货地址,必须通过mounted的全局变量传过来,因为传来的是aid不是aid的展示序号
                PayBtnAid:'',    //初始化默认收货地址,因为没有改变所以没有执行全局变量的传输,add的mounted可以传但是也可以在此自定义
                routerdata:''
            }
        },
        methods:{
            HavedOrder(){
                if(this.PayBtnCids!='' && this.PayBtnAid!=''){
                    this.routerdata=`aid=${this.PayBtnAid}&${this.PayBtnCids}`
                    this.$addr.get(`orders/create?${this.routerdata}`).then(
                        response=>{
                            console.log('请求下单成功了',response)
                            this.$router.push({
                                name:'PxPay',
                                params:{oid:response.data.data.oid}})
                        },
                        error=>{
                            console.log('请求下单失败了',error.message)
                        }
                    )
                }else{
                    this.$notify.warning({
                        title: '提示',
                        message: '您未选择收货地址',
                        showClose:false,
                        duration:2000,
                    });
                    console.log('自动勾选收货地址或者获取勾选的购物车数据出异常了');
                }
            }
        },
        mounted(){
            this.$bus.$on('TransferCheckedCart',(data)=>{
                for(let i=0 ; i<data.length ; i++){
                    if( i != data.length-1){
                        this.PayBtnCids+=`cids=${data[i].cid}&`
                    }else{
                        this.PayBtnCids+=`cids=${data[i].cid}`
                    }
                }
            })
            this.$bus.$on('TransferCheckedAddress',(data)=>{
                this.PayBtnAid=data
            })
        },
        beforeDestroy(){
            this.$bus.$off('TransferCheckedCart')
            this.$bus.$off('TransferCheckedAddress')
        }
    }
</script>

<style scoped>
.PBSdiv1{
    margin: 0 auto;
    max-width: 1000px;
    border-left: 1px solid rgb(179, 179, 179 , 0.7);
    border-right: 1px solid rgb(179, 179, 179 , 0.7);
    border-bottom: 1px solid rgb(179, 179, 179 , 0.7);
    position: fixed;
    bottom: 0px;
}
.myCreateOrderrow15{
    margin: 0 auto;
    max-width: 1000px;
    height: 100%;
    font-size: 14px;
}
.myCreateOrdercol15Left{
    height: 50px;
    background-color: rgb(236, 236, 236);
}
.PBSdiv2{
    opacity: 0.7;
    font-size: 14px;
    float: right;
    margin-top: 16px;
    margin-right: 15px;
}
.myCreateOrdercol15Right{
    width: 220px;
    background-color: rgb(228, 67, 102);
    text-align: center;
    cursor: pointer;
    user-select: none;
}
.PBSdiv3{
    font-size: 20px;
    color: white;
    margin-top: 11px;
}
.COpaytime{
    margin-left: 8px;
    font-size: 13px;
}
</style>